//
//  ForumDataTool.m
//  JiaoX
//
//  Created by yinqy on 15/2/27.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "ForumDataTool.h"

@implementation ForumDataTool

+(void)getHomeDataWithModelId:(NSString *)modelId pageIndex:(int)pageIndex lastId:(NSString *)lastId modulePostsType:(int)type success:(void (^)(BBSHomeData *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:modelId forKey:@"moduleId"];
    [param setObject:[NSNumber numberWithInt:pageIndex] forKey:@"pageIndex"];
    [param setObject:lastId forKey:@"lastId"];
    [param setObject:[NSNumber numberWithInt:type] forKey:@"modulePostsType"];
    [self postWithUrl:[NSString stringWithFormat:@"%@forum/index",BASE_URL] param:param hasT:NO resultClass:[BBSHomeData class] success:success failure:failure];
}

+(void)getMineInteractDataWithUrl:(NSString *)url lastTime:(NSString *)lastTime replyType:(NSString *)replyType success:(void (^)(MineInteractResult *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    if (![replyType isEqualToString:@"-1"]) {
        [param setObject:replyType forKey:@"replyType"];
    }
    [param setObject:lastTime forKey:@"createTime"];
    [self postWithUrl:url param:param hasT:YES resultClass:[MineInteractResult class] success:success failure:failure];
}

+(void)getPostsInfoWithPostsId:(NSString *)postsId lastComtId:(NSString *)lastComtId posterType:(int)posterType orderBy:(NSString *)orderBy success:(void (^)(PostsDetailsResult *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:postsId forKey:@"postsId"];
    [param setObject:lastComtId forKey:@"lastComtId"];
    [param setObject:[NSString stringWithFormat:@"%d",posterType] forKey:@"posterType"];
    [param setObject:orderBy forKey:@"orderBy"];
    [self postWithUrl:[NSString stringWithFormat:@"%@forum/postsDetail",BASE_URL] param:param hasT:NO resultClass:[PostsDetailsResult class] success:success failure:failure];
}

+(void)publishNewTopicWithTitle:(NSString *)title content:(NSString *)content modelId:(NSString *)modelId imageUrls:(NSString *)imageUrls prodId:(NSString *)prodId success:(void (^)(JXBaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    
    [param setObject:title forKey:@"title"];
    [param setObject:content forKey:@"content"];
    [param setObject:modelId forKey:@"modelId"];
    [param setObject:imageUrls forKey:@"imgPaths"];
    if (!ISBLANK(prodId)) {
        [param setObject:prodId forKey:@"prodId"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@forum/addPosts",BASE_URL] param:param hasT:YES resultClass:[JXBaseResponse class] success:success failure:failure];
}

+(void)getComtDetailListWithComtId:(NSString *)commentId lastComtId:(NSString *)lastComtId url:(NSString *)url  success:(void (^)(CommentInfo *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    
    [param setObject:commentId forKey:@"commentId"];
    [param setObject:lastComtId forKey:@"lastComtId"];
    if ([url isEqualToString:@"forum/commentDetail"]) {
        [param setObject:@"asc" forKey:@"orderBy"];
    }
    [self postWithUrl:[NSString stringWithFormat:@"%@%@",BASE_URL,url] param:param hasT:NO resultClass:[CommentInfo class] success:success failure:failure];
}

+(void)getChatSignatureWithAppId:(NSString *)appId peerId:(NSString *)peerId success:(void (^)(ChatSignature *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:appId forKey:@"appId"];
    [param setObject:peerId forKey:@"peer_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@im/masterKey",BASE_URL] param:param hasT:YES resultClass:[ChatSignature class] success:success failure:failure];
}

+(void)reportUserWithUserId:(NSString *)userId success:(void (^)(JXBaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:userId forKey:@"reportId"];
    [self postWithUrl:[NSString stringWithFormat:@"%@im/reportUser",BASE_URL] param:param hasT:YES resultClass:[JXBaseResponse class] success:success failure:failure];
}

+(void)getModeList:(void (^)(BBSHomeData *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@forum/modelList",BASE_URL] param:param hasT:NO resultClass:[BBSHomeData class] success:success failure:failure];
}

+(void)getForumUserInfoWithUserId:(NSString *)userId pageIndex:(NSInteger)pageIndex success:(void (^)(PersonInfo *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [param setObject:userId forKey:@"userId"];
    [param setObject:[NSNumber numberWithInteger:pageIndex] forKey:@"pageIndex"];
    [self postWithUrl:[NSString stringWithFormat:@"%@forum/userInfo",BASE_URL] param:param hasT:NO resultClass:[PersonInfo class] success:success failure:failure];
}

+(void)getforumSupPoint:(void (^)(Integral *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionaryWithDictionary:[[[JXBaseRequest alloc]init] keyValues]];
    [self postWithUrl:[NSString stringWithFormat:@"%@forum/supPoint",BASE_URL] param:param hasT:YES resultClass:[Integral class] success:success failure:failure];
}

@end
